<template>
    <div>
        <Card title="新增/编辑品牌" :bordered="false" dis-hover class="ivu-mt">
            <Form ref="formData" :model="formData" :rules="dynamicData.formDataRules" :label-width="140">
                <Row>
                    <Col span="18" offset="3" v-for="(item, index) in copyFormData" :key="index">
                        <component :itemData="item.data" v-bind:is="item.fileName" @handleChangeFormData="handleChangeFormData"></component>
                    </Col>
                    <Col span="18" offset="3">
                        <FormItem>
                          <Button type="primary" @click="handleSubmit('formData')">提交</Button>
                          <Button @click="handleReset('formData')" class="ivu-ml-8">清空</Button>
                        </FormItem>
                    </Col>
                </Row>
            </Form>
        </Card>
    </div>
</template>
<script>
    import util from '@/libs/util';
    import { dynamicData } from './dynamicComp/dynamicNewEditConfig'; // 组件配置文件
    import forms from '@/mixins/dynamicform'; // 混入通用代码

    export default {
        mixins: [forms],
        components: {
            ...util.Pub.dynamicComps(dynamicData.formData)
        },
        data () {
            return {
                dynamicData: dynamicData // 配置的数据
            }
        },
        methods: {
            // 提交
            handleSubmit (name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        this.$Message.success('成功!');
                    } else {
                        this.$Message.error('失败!');
                    }
                })
            },
            // 清空表单
            handleReset (name) {
                let copyFormData = JSON.parse(JSON.stringify(this.dynamicData.formData));
                this.$set(this, 'copyFormData', copyFormData);
                // this.$refs[name].resetFields();
            }
        }
    }
</script>
<style lang="less" scoped>
</style>
